package com.zbkj.front.controller;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.order.*;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.UploadResponse;
import com.zbkj.common.response.order.*;
import com.zbkj.front.service.OrderHandleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Auther:
 * @Date: 2024/9/15 16:40
 * @Description:
 */
@CrossOrigin("*")
@RestController
@RequestMapping("api/front/order")
@Api(tags = "客户端订单(充值)服务")
public class OrderController {
    @Autowired
    private OrderHandleService orderHandleService;

    @ApiOperation(value = "充值页获取用户流量包信息")
    @GetMapping(value = "/getUserRechargeInfo")
    public CommonResult<UserRechargeResponse> getUserRechargeInfo() {
        return CommonResult.success(orderHandleService.getUserRechargeInfo());
    }

    @ApiOperation(value = "订单列表")
    @PostMapping(value = "/getOrderList")
    public CommonResult<CommonPage<ClientOrderResponse>> getOrderList(@RequestBody PageParamRequest paramRequest) {
        return CommonResult.success(CommonPage.restPage(orderHandleService.getOrderList(paramRequest)));
    }

    @ApiOperation(value = "充值订单保存")
    @PostMapping(value = "/orderSave")
    public CommonResult<OrderSucceResponse> orderSave(@RequestBody @Validated ClientOrderSaveRequest saveRequest) {
        return CommonResult.success(orderHandleService.orderSave(saveRequest));
    }

    @ApiOperation(value = "告申请下单页获取(项目及支付配置信息)")
    @GetMapping(value = "/getReportPayConf/{projectId}")
    public CommonResult<ReportOrderPayResonse> getReportPayConf(@PathVariable("projectId") Long projectId) {
        return CommonResult.success(orderHandleService.getReportPayConf(projectId));
    }

    /*@ApiOperation(value = "告申请下单页-流量包支付(项目及支付信息)")
    @GetMapping(value = "/getReportPayFlowPacketConf/{projectId}")
    public CommonResult<ReportOrderPayResonse> getReportPayFlowPacketConf(@PathVariable("projectId") Long projectId) {
        return CommonResult.success(orderHandleService.getReportPayFlowPacketConf(projectId));
    }*/

    @ApiOperation(value = "报告购买订单保存")
    @PostMapping(value = "/reportOrderSave")
    public CommonResult<OrderSucceResponse> reportOrderSave(@RequestBody @Validated ClientReportOrderSaveRequest saveRequest) {
        return CommonResult.success(orderHandleService.reportOrderSave(saveRequest));
    }

    @ApiOperation(value = "报告申请-流量包支付保存")
    @GetMapping(value = "/reportPayFlowPacketSave/{projectId}")
    public CommonResult reportPayFlowPacketSave(@PathVariable("projectId") Long projectId) {
        orderHandleService.reportPayFlowPacketSave(projectId);
        return CommonResult.success();
    }

    @ApiOperation(value = "订单保存获取支付信息")
    @GetMapping(value = "/getOrderPayment/{orderNo}")
    public CommonResult<ClientOrderResponse> getOrderPayment(@PathVariable("orderNo") String orderNo) {
        return CommonResult.success(orderHandleService.getOrderPayment(orderNo));
    }

    @ApiOperation(value="支付凭证上传")
    @PostMapping("/payVoucheUpload")
    public CommonResult<UploadResponse> payVoucheUpload(MultipartFile file) {
        return CommonResult.success(orderHandleService.payVoucheUpload(file));
    }

    @ApiOperation(value="支付凭证保存")
    @PostMapping("/payVoucheSave")
    public CommonResult payVoucheSave(@RequestBody @Validated OrderPayVoucheSaveRequest saveRequest) {
        orderHandleService.payVoucheSave(saveRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "取消订单")
    @GetMapping(value = "/cancel/{orderNo}")
    public CommonResult cancel(@PathVariable("orderNo") String orderNo) {
        orderHandleService.cancel(orderNo);
        return CommonResult.success();
    }

    @ApiOperation(value = "可开票")
    @PostMapping(value = "/invoice/list")
    public CommonResult<CommonPage<InvoiceListResponse>> invoiceList(@RequestBody InvoiceListQueryRequest invoiceListQueryRequest) {
        return CommonResult.success(CommonPage.restPage(orderHandleService.invoiceList(invoiceListQueryRequest)));
    }

    @ApiOperation(value = "提交开票申请")
    @PostMapping(value = "/invoice/apply")
    public CommonResult apply(@RequestBody @Validated InvoiceApplySaveRequest invoiceApplySaveRequest) {
        if(orderHandleService.apply(invoiceApplySaveRequest)){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation(value = "开票记录")
    @PostMapping(value = "/invoice/history")
    public CommonResult<CommonPage<InvoiceHistoryListResponse>> invoiceHistoryList(@RequestBody PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(orderHandleService.invoiceHistoryList(pageParamRequest)));
    }
}
